using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input.Touch;

namespace PiratesOfBermuda
{
    public class BasicEnemy : Ship
    {
        Random random;

        public BasicEnemy(Game game, SpriteBatch spriteBatch, int x, int y)
            : base(game, spriteBatch)
        {
            this.X = x;
            this.Y = y;
            _name = "BasicEnemy";
        }

        public override void Initialize()
        {
            base.Initialize(@"Textures/MainGameplay/redpirate", new Rectangle(0, 0, 50, 50), new Point(1, 8), new Point(X, Y));
            random = new Random();
            base.Initialize();
        }

        public Point GetNextMove(int playerX, int playerY)
        {
            int deltaX = Math.Abs(X - playerX);
            int deltaY = Math.Abs(Y - playerY);
            Point returnPoint = new Point(X, Y);
            int side = -1;

            if (deltaX == deltaY)
            {
                side = random.Next(0, 9)%2;
            }

            if (deltaX > deltaY || side == 0)
            {
                if (playerX > X)
                    returnPoint.X = X + 1;
                else
                    returnPoint.X = X - 1;
            }
            else if (deltaY > deltaX || side == 1)
            {
                if (playerY > Y)
                    returnPoint.Y = Y + 1;
                else
                    returnPoint.Y = Y - 1;
            }

            return returnPoint;
        }
        public Point GetNextMove(int player1X, int player1Y, int player2X, int player2Y)
        {
            double d = (double)(Math.Pow(X - player1X, 2) + Math.Pow(Y - player1Y, 2));

            double distance1 = Math.Sqrt(d);
            d = (double)(Math.Pow(X - player2X, 2) + Math.Pow(Y - player2Y, 2));
            double distance2 = Math.Sqrt(d);

            int playerX = 0, playerY = 0;
            int side = -1;
            if (distance1 == distance2)
            {
                side = random.Next(0, 9) % 2;
            }
            if (distance1 < distance2 || side == 0)
            {
                playerX = player1X;
                playerY = player1Y;
            }
            else if (distance1 > distance2 || side == 1 )
            {
                playerX = player2X;
                playerY = player2Y;
            }


            int deltaX = Math.Abs(X - playerX);
            int deltaY = Math.Abs(Y - playerY);
            Point returnPoint = new Point(X, Y);
            
            if (deltaX == deltaY)
            {
                side = random.Next(0, 9)%2;
            }

            if (deltaX > deltaY || side == 0)
            {
                if (playerX > X)
                    returnPoint.X = X + 1;
                else
                    returnPoint.X = X - 1;
            }
            else if (deltaY > deltaX || side == 1)
            {
                if (playerY > Y)
                    returnPoint.Y = Y + 1;
                else
                    returnPoint.Y = Y - 1;
            }

            return returnPoint;

            
        }
    }
}
